﻿{extend name="/public/base" /}
{block name="header"}{/block}
{block name="menu"}{/block}

{block name="main"}
<article class="cl pd-20">
	<form method="post" action="{:url('role/create')}" class="form form-horizontal" id="form-role-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="name" name="name" datatype="*4-16" nullmsg="用户名不能为空">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">备注：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="comments" class="textarea" placeholder="说点什么...100个字符以内" dragonfly="true"></textarea>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">权限分配：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<dl class="cl permission-list">
					<dt>
						<label>
							<input type="checkbox" value="">全选
						</label>
					</dt>
					<dd>
						{volist name="module" id="vo"}
						<label class="">
							<input type="checkbox" value="{$vo.id}" name="node[]" id="{$vo.id}">{$vo.module_name}
						</label>
						{/volist}
					</dd>
				</dl>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="role-save" name="role-save"><i class="icon-ok"></i>确定</button>
			</div>
		</div>
	</form>
</article>
{/block}

{block name="_footer"}
{js href="/static/backend/lib/jquery.validation/1.14.0/jquery.validate.js" /}
{js href="/static/backend/lib/jquery.validation/1.14.0/validate-methods.js" /}
{js href="/static/backend/lib/jquery.validation/1.14.0/messages_zh.js" /}
<script type="text/javascript">
$(function(){
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});

	$("#form-role-add").validate({
		rules:{
			name:{
				required:true,
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url:"{:url('role/create')}",
				success: function(data){
					layer.alert(data.message,{icon:1,time:3000}, function () {
						var index = parent.layer.getFrameIndex(window.name);
						parent.location.reload();
						parent.layer.close(index);
					});
				}
			});

			return false;
		}
	});
});
</script>
{/block}